#pragma once
//#include <guichan.hpp>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>


#include <QTextEdit>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QDockWidget>
#include <QKeyEvent>
#include <QGLViewer/qglviewer.h>


extern "C"
{
	#include "lua.h"
	#include "lualib.h"
	#include "lauxlib.h"
	extern int luaopen_console(lua_State* L);
	extern int luaopen_baijiAccessor(lua_State* L);
	extern int luaopen_meshManager(lua_State* L);
	extern int luaopen_mesh(lua_State* L);
}


class Console : public QDockWidget
{
	Q_OBJECT

	public slots:
		void interpretLua();

	private:
		QVBoxLayout* vertBox;
		QTextEdit* textBox;
		QLineEdit* luaPrompt;

		std::vector<std::string> historic;
		unsigned int hIdx;
		lua_State *L;
		unsigned int maxHist;

	public:
		Console(QWidget * parent = 0);
        void init(void);
		inline ~Console(void);

		void keyPressEvent(QKeyEvent *e);

		void print(char* txt);
		inline QTextEdit* getTextBox() {return textBox;};
		inline QLineEdit* getLuaPrompt() {return luaPrompt;};
		inline static void tintin() {std::cout << "tintin" << std::endl;};
};
